const axios1 = require('axios')
var axios = axios1.create({
  baseURL: 'http://43.138.142.86:3000',
  timeout: 5000
})
const status = false
// 请求前拦截
axios.interceptors.request.use((config) => {
  // const token = JSON.parse(localStorage.getItem('userinfo')).token
  // config.headers.common['Authorization'] = `Bearer ${token}`
  return config
}, (err) => {

})
// 请求数据返回前拦截
axios.interceptors.response.use((res) => {
  return res
})

const get = function (...args) {
  const [url, params] = args
  return new Promise((resolve, reject) => {
    axios.get(url, { params })
      .then((res) => {
        resolve(res.data)
      })
      .catch((err) => {
        reject('get请求失败')
      })
  })
}
const post = (...args) => {
  const [url, params] = args

  return new Promise((resolve, reject) => {
    axios.post(url, params)
      .then((res) => {
        resolve(res.data)
      })
      .catch((err) => {
        reject('post请求失败')
      })
  })
}

module.exports = {
  get,
  post
}
